package com.ruoyi.web.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * APP 结果集返回处理类
 *
 * @author ZERO
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultInfo<T> {
    /**
     * 状态
     */
    private Integer status;

    /**
     * 消息内容
     */
    private String msg;

    /**
     * 数据集合
     */
    private T data = (T) "";

    /**
     * 兼容 layui
     */
    private Long count = 0L;
    @JsonIgnore
    private String dataId = "0";
    @JsonIgnore
    private Long[] dataIds;
    @JsonIgnore
    private List<Long> energyDataId;


    public ResultInfo(ResultStatus status) {
        this.status = status.getCode();
        this.msg = status.getName();
    }
    public ResultInfo(ResultStatus status, String msg, T data) {
        this(status, msg);
        this.data = data;
    }
    public ResultInfo(ResultStatus status, String msg) {
        this(status);
        this.msg = msg;
    }

    public ResultInfo(ResultStatus status, String msg, List<Long> energyDataId) {
        this(status);
        this.msg = msg;
        this.energyDataId = energyDataId;
    }


    public ResultInfo(ResultStatus status, String msg, Long count, T data) {
        this(status, msg);
        this.data = data;
        this.count = count;
    }

    public ResultInfo(ResultStatus status, String msg, String dataId, T data) {
        this(status, msg);
        this.data = data;
        this.dataId = dataId;
    }

    public ResultInfo(ResultStatus status, String msg, Long count, Long[] dataIds, T data) {
        this(status, msg);
        this.data = data;
        this.dataIds = dataIds;
        this.count = count;
    }

    public ResultInfo(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public ResultInfo(ResultStatus status, String msg, Long count, T data, List<Long> energyDataId) {
        this(status, msg);
        this.data = data;
        this.count = count;
        this.energyDataId = energyDataId;
    }


    public static <T> ResultInfo<T> ok() {
        return okWith(ResultStatus.SUCCESS.getName());
    }

    public static <T> ResultInfo<T> okWith(String msg) {
        return ok(msg, 0L, (T) null);
    }

    public static <T> ResultInfo<T> ok(T data) {
        return ok(ResultStatus.SUCCESS.getName(), data);
    }

    public static <T> ResultInfo<T> ok(String msg, T data) {
        return ok(msg,0L, data);
    }

    public static <T> ResultInfo<T> ok(String msg, T data, List<Long> energyDataId) {
        return ok(msg,0L, data,energyDataId);
    }


    public static <T> ResultInfo<T> ok(String msg, Long count, T data) {
        return new ResultInfo<>(ResultStatus.SUCCESS, msg,count, data);
    }

    public static <T> ResultInfo<T> ok(String msg,String dataId, T data) {
        return new ResultInfo<>(ResultStatus.SUCCESS, msg,dataId, data);
    }

    public static <T> ResultInfo<T> ok(String msg,Long count,Long[] dataIds, T data) {
        return new ResultInfo<>(ResultStatus.SUCCESS, msg,count,dataIds, data);
    }

    public static <T> ResultInfo<T> ok(String msg,Long count, T data,List<Long> energyDataId) {
        return new ResultInfo<>(ResultStatus.SUCCESS, msg,count, data,energyDataId);
    }

    public static <T> ResultInfo<T> error() {
        return error(ResultStatus.FAIL.getName());
    }

    public static <T> ResultInfo<T> error(String msg) {
        return error(ResultStatus.FAIL, msg);
    }
    public static <T> ResultInfo<T> error(String msg, T data) {
        return error(ResultStatus.FAIL, msg, data);
    }
    public static <T> ResultInfo<T> error(String msg,List<Long> energyDataId) {
        return error(ResultStatus.FAIL, msg,energyDataId);
    }

    public static <T> ResultInfo<T> error(ResultStatus code, String msg) {
        return new ResultInfo<>(code, msg);
    }

    public static <T> ResultInfo<T> error(Integer status, String msg) {
        return new ResultInfo<>(status, msg);
    }

    public static <T> ResultInfo<T> error(ResultStatus status, String msg, List<Long> energyDataId) {
        return new ResultInfo<>(status, msg,energyDataId);
    }

    public static <T> ResultInfo<T> error(ResultStatus status, String msg, T data) {
        return new ResultInfo<>(status, msg, data);
    }

    public static <T> ResultInfo<T> test(boolean test) {
        return test ? ok() : error();
    }

    public static <T> ResultInfo<T> test(boolean test, String msg) {
        return test ? ok() : error(msg);
    }


}
